# -*- coding: utf-8 -*-
#爪子模块
#负责控制爪子的开合与状态获取

##############################################
import time
import restoration.command as command

#定义爪子张开的标志
CLAW_OPEN=0 
#定义爪子关闭的标志
CLAW_CLOSE=1
#爪子当前状态
claw_1_state=CLAW_OPEN;
claw_2_state=CLAW_OPEN;

#设置一个爪子的状态
def setOneClawState(num,state):
    #判断是否需要进行状态变化
    #if getClawState(num)==state:
     #   return
    #开始进行状态改变
    global claw_1_state;
    global claw_2_state;
    if num==1:
        if state==CLAW_OPEN:
            #print("1:open");
            claw_1_state=CLAW_OPEN;
            command.setClawState(1,"open");
        else:
            #print("1:close");
            claw_1_state=CLAW_CLOSE;
            command.setClawState(1,"close");
    else:
        if state==CLAW_OPEN:
            #print("2:open");
            claw_2_state=CLAW_OPEN;
            command.setClawState(2,"open");
        else:
            #print("2:close");
            claw_2_state=CLAW_CLOSE;
            command.setClawState(2,"close");

#获取爪子的状态
def getClawState(num):
    if num==1:
        return claw_1_state;
    else :
        return claw_2_state;

#设置两个爪子的状态
def setClawsState(state1,state2):
    if state1==CLAW_OPEN:
        if state2==CLAW_OPEN:
            command.setClawState("open","open");
        else:
            command.setClawState("open","close");
    else:
        if state2==CLAW_OPEN:
            command.setClawState("close","open");
        else:
            command.setClawState("close","close");
